import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layout'

// import departmentsRouter from './compoments/departments'
import employess from './compoments/employess'
import permission from './compoments/permission'

Vue.use(Router)

/* Layout */

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/login',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: 'Dashboard', icon: 'dashboard' }
      }
    ]
  },
  {
    path: '/uploadexcel',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        name: 'uplad',
        component: () => import('@/views/uploadExcel/index')
      }
    ]
  },
  // 组织架构模块
  {
    path: '/departments',
    component: Layout,
    children: [
      {
        path: '',
        name: 'departments',
        component: () => import('@/views/departments'),
        meta: { title: '组织架构', icon: 'tree' }
      }
    ]
  },
  // 组织架构模块
  {
    path: '/setting',
    component: Layout,
    children: [
      {
        path: '',
        name: 'setting',
        component: () => import('@/views/setting'),
        meta: { title: '公司设置', icon: 'setting' }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    // routes: [...constantRoutes, ...asyncRoutes]
    routes: [...constantRoutes, employess, permission]
  })

const router = createRouter()

export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
